#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define MaxSize 100

typedef int ElemType;
typedef struct Stack{
    ElemType data;
    struct Stack *next;
}LStack;

bool initStack(LStack *S);
bool push(LStack *S, ElemType elem);
bool pop(LStack *S, ElemType *elem);

int main(){
    LStack S;
    int elem;
    push(&S, 100);
    printf("%d\n", S.next->data);
    pop(&S, &elem);
    printf("%d\n", elem);
    return 0;
}

//带头节点
bool initStack(LStack *S){
    S = (ElemType *)malloc(sizeof(ElemType));
    if(S==NULL) return false;
    S->next = NULL;
    return true;
}

bool push(LStack *S, ElemType elem){
    if(S==NULL) return false;
    LStack *p = S;
    LStack *temp = (ElemType *)malloc(sizeof(ElemType));
    if(temp==NULL) return false;
    temp->data = elem;
    temp->next = p->next;
    p->next = temp;
    return true;
}

bool pop(LStack *S, ElemType *elem){
    if(S==NULL) return false;
    LStack *p = S;
    *elem = p->next->data;
    LStack *q = p->next;
    p->next = q->next;
    free(q);
    return true;
}